//source /u/miranov/.baliceTPC

void drawDoubleTrack(const Double_t pc0=1, const TString tag=""){
  const Double_t pc1 = pc0 + 100;

  gStyle->SetOptStat("enoum");

  //gStyle->SetOptTitle(0);

  TChain *chain = AliXRDPROOFtoolkit::MakeChainRandom("LHC10de.list","V0s" ,0,10000000);
  //TChain *chain = AliXRDPROOFtoolkit::MakeChainRandom("LHC10de.list","V0s" ,0,1);

  chain->SetAlias("drphi", "abs( track0.fIp.GetParameterAtRadius(85,5,8)-track1.fIp.GetParameterAtRadius(85,5,8) )*85");
  //chain->SetAlias("drphi", "abs( track0.GetParameterAtRadius(85,5,8)-track1.GetParameterAtRadius(85,5,8) )*85");
  //chain->SetAlias("drphi", "abs( track0.fIp.Phi()-track1.fIp.Phi() )*85");
  chain->SetAlias("dz","abs(track0.fIp.fP[1]-track1.fIp.fP[1])");

  chain->SetAlias("dist2D","sqrt( dz*dz + drphi*drphi )");

  //chain->SetAlias("cutEle", Form(" type==1 && track0.fIp.P()> %e && track0.fIp.P()< %e && track1.fTPCsignal>70 && dz<0.2 && drphi < 20 && abs(track0.Eta())<0.6 && abs(track0.Eta())>0.4", pc0, pc1));
  //chain->SetAlias("cutEle", Form(" type==1 && track0.fIp.P()> %e && track0.fIp.P()< %e && track1.fTPCsignal>70 && dz<0.2 && drphi < 20 && abs(track0.Eta())<0.2", pc0, pc1));
  chain->SetAlias("cutEle", Form(" type==1 && track0.fIp.P()> %e && track0.fIp.P()< %e && track1.fTPCsignal>70 && dz<0.2 && drphi < 20 && abs(track0.Eta())<0.6", pc0, pc1));

  //const TString cut(Form("#gamma#rightarrow ee, p_{e} > %.1f GeV/c, 0.4 < |#eta_{e}| < 0.6", pc0));
  //const TString cut(Form("#gamma#rightarrow ee, p_{e} > %.1f GeV/c, |#eta_{e}| < 0.2", pc0));
  const TString cut(Form("#gamma#rightarrow ee, p_{e} > %.1f GeV/c, |#eta_{e}| < 0.6", pc0));

  //================================================
  ceta = new TCanvas;

  chain->Draw("abs(track0.Eta()):dist2D>>eta(20,0,20, 30, 0, 0.9)","cutEle","colz");

  ceta->Print(tag+Form("eta_pc%.0f_%.0f.eps", pc0, pc1));
  ceta->Print(tag+Form("eta_pc%.0f_%.0f.root", pc0, pc1));

  //================================================
  cmass = new TCanvas;

  chain->Draw("GetEffMass(0,0):dist2D>>mass(20,0,20, 100, 0, 0.12)","cutEle","colz");

  cmass->Print(tag+Form("mass_pc%.0f_%.0f.eps", pc0, pc1));
  cmass->Print(tag+Form("mass_pc%.0f_%.0f.root", pc0, pc1));

  //================================================

  czrphi = new TCanvas; 

  chain->Draw("dz:drphi>>zrphi(50,0,20, 50, 0,0.2)","cutEle","colz");

  zrphi->SetTitle(cut+";r_{TPC inner}d#phi (cm);dz (cm)");
  zrphi->Draw("colz");

  czrphi->Print(tag+Form("zrphi_pc%.0f_%.0f.eps", pc0, pc1));
  czrphi->Print(tag+Form("zrphi_pc%.0f_%.0f.root", pc0, pc1));

  //===================================================

  gStyle->SetOptStat(0);

  c2D = new TCanvas;

  chain->Draw("track0.fTPCsignal:dist2D>>Q2D(30,0,15, 120,50, 110)","cutEle","colz");

  Q2D->SetTitle(cut+";#sqrt{(r_{TPC inner}d#phi)^{2}+dz^{2}} (cm);TPC electron signal");
  Q2D->GetXaxis()->SetTitleOffset(1.2);
  Q2D->Draw("colz");

  c2D->Print(tag+Form("2D_pc%.0f_%.0f.eps", pc0, pc1));
  c2D->Print(tag+Form("2D_pc%.0f_%.0f.root", pc0, pc1));

  //TF1 * fgaus = new TF1("fgaus","[0]*TMath::Gaus(x,[1],[2],1)",60,110);
  //fgaus->SetParameters(100,75,4);

  Q2D->FitSlicesY();//fgaus);

  c2Dmean = new TCanvas;
  Q2D_1->SetMinimum(70);
  Q2D_1->SetMaximum(90);
  Q2D_1->SetTitle(cut+";#sqrt{(r_{TPC inner}d#phi)^{2}+dz^{2}} (cm);mean TPC electron signal");
  Q2D_1->SetMarkerStyle(20);
  Q2D_1->SetMarkerSize(1);
  Q2D_1->GetXaxis()->SetTitleOffset(1.2);
  gPad->SetGrid();
  Q2D_1->Draw();

  c2Dmean->Print(tag+Form("2Dmean_pc%.0f_%.0f.eps", pc0, pc1));
  c2Dmean->Print(tag+Form("2Dmean_pc%.0f_%.0f.root", pc0, pc1));

  return;

  //===================================================

  cdz = new TCanvas;

  chain->Draw("meanQ:dz>>Qdz(20,0,20, 100,60,100)","cutEle && drphi<0.5","colz");

  Qdz->FitSlicesY();

  cdzmean = new TCanvas;
  Qdz_1->Draw();

  //================================================ 

  cdrphi = new TCanvas;

  chain->Draw("meanQ:drphi>>Qdrphi(20,0,20, 100,60,100)","cutEle && dz<0.5","colz");

  Qdrphi->FitSlicesY();

  cdrphimean = new TCanvas;
  Qdrphi_1->Draw();

  //chain->Draw("abs(track0.fP[3]):dist2D>>his(10,0,10)","type==1&&track0.fIp.P()>0.5&&abs(track0.fIp.fP[3])<1","prof",10000);
}
